/*h5页面*/
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';
import '../utility/sq_color.dart';
import '../views/appbar_black.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class WebViewPage extends StatefulWidget {
  late String title;
  late String url;

  @override
  State<StatefulWidget> createState() => WebviewState();

  WebViewPage(this.title, this.url);
}

class WebviewState extends State<WebViewPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: AnnotatedRegion(
        value: SystemUiOverlayStyle.dark,
        child: Container(
          child: Column(
            children: [
              AppbarCenterTitle(
                title: widget.title,
                imgStr: 'image/imv_back.png',
                titleColor: SQColor.black,
              ),
              Expanded(
                  child: WebView(
                initialUrl: widget.url,
                onPageStarted: (str) {
                  EasyLoading.show(status: '加载中...');
                },
                onPageFinished: (str) {

                  EasyLoading.dismiss();
                },
                javascriptMode: JavascriptMode.unrestricted,
                // javascriptChannels: _jsCallNativeChannel(),
                // gestureNavigationEnabled: true,
              ))
            ],
          ),
        ),
      ),
    );
  }

  _jsCallNativeChannel() {
    return <JavascriptChannel>[
      _jsCallNativeJavascriptChannel(context),
    ].toSet();
  }

  _jsCallNativeJavascriptChannel(BuildContext context) {
    return JavascriptChannel(
        name: "postStatus",
        onMessageReceived: (JavascriptMessage message) {
          print("Js call native ：${message.message}");
        });
  }

  @override
  void dispose() {
    if(EasyLoading.isShow){
      EasyLoading.dismiss();
    }
    super.dispose();
  }
}
